#!/bin/bash
# 重启当前模式的服务

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# 读取当前模式
MODE=$(cat /tmp/browse-etl-mode 2>/dev/null || echo "consumer")

echo "🔄 重启服务（当前模式: $MODE）..."
echo "=================================================="

# 停止所有服务
"$SCRIPT_DIR/stop-all.sh"

# 根据模式启动对应服务
case "$MODE" in
    flink-local)
        echo ""
        echo "🚀 启动 Flink Agents 本地模式..."
        "$SCRIPT_DIR/start-flink-local.sh"
        ;;
    flink-cluster)
        echo ""
        echo "🚀 启动 Flink Agents 集群模式..."
        "$SCRIPT_DIR/start-flink-cluster.sh"
        ;;
    flink)
        # 向后兼容旧的 flink 模式，映射到 flink-local
        echo ""
        echo "🚀 启动 Flink Agents 本地模式..."
        "$SCRIPT_DIR/start-flink-local.sh"
        ;;
    *)
        echo ""
        echo "🚀 启动 consumer.py 模式..."
        "$SCRIPT_DIR/start-all.sh"
        ;;
esac

echo ""
echo "✅ 服务已重启（模式: $MODE）"
echo "=================================================="

